<%@ page import="com.example.softwareconfigurationcoursedesign.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>搜索结果</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }

        table, th, td {
            border: 1px solid black;
        }

        th, td {
            padding: 8px;
            text-align: left;
        }
    </style>
</head>
<body>
<h1>搜索结果</h1>

<table id="searchResultsTable">
    <%
        Connection connection;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String jdbcUrl = "jdbc:mysql://localhost:3306/course_design";
            String username = "root";
            String password = "123456";
            connection = DriverManager.getConnection(jdbcUrl, username, password);
            connection.createStatement();
        } catch (Exception ignored) {
        } finally {
        }
    %>
    <tr>
        <th>ID</th>
        <th>产品ID</th>
        <th>产品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>URL</th>
        <th>详情</th>
    </tr>
    <%
        List<Product> searchResults = (List<Product>) request.getAttribute("searchResults");
        if (searchResults != null) {
            for (Product product : searchResults) {
    %>
    <tr>
        <td><%= product.getId() %>
        </td>
        <td><%= product.getPid() %>
        </td>
        <td><%= product.getPname() %>
        </td>
        <td><%= product.getPprice() %>
        </td>
        <td><%= product.getPtag() %>
        </td>
        <td><%=product.getPurl()%>
        </td>
        <td><%= product.getDetail() %>
        </td>
    </tr>
    <%
            }
        }
    %>
</table>

</body>
</html>